﻿#include "dialogusermdify.h"
#include "ui_dialogusermdify.h"
#include"Tool/qfilehelper.h"
DialogUserMdify::DialogUserMdify(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogUserMdify)
{
    ui->setupUi(this);
    connect(ui->btn_iconSel,SIGNAL(clicked(bool)),this,SLOT(slotBtnIconSelect()));
    connect(ui->btn_showHide,SIGNAL(clicked(bool)),this,SLOT(slotBtnShowHide()));
    connect(ui->btn_accept,SIGNAL(clicked(bool)),this,SLOT(slotBtnAccept()));
    connect(ui->btn_reject,SIGNAL(clicked(bool)),this,SLOT(slotBtnReject()));

}

DialogUserMdify::~DialogUserMdify()
{
    delete ui;
}

void DialogUserMdify::setUserInfo(const UserInfo &userInfo)
{
    m_userInfo=userInfo;
    showUserInfo();
}

UserInfo DialogUserMdify::GetUserInfo()
{
    return m_userInfo;
}

void DialogUserMdify::slotBtnAccept()
{
    setUserInfo();
    accept();
}

void DialogUserMdify::slotBtnReject()
{
    reject();
}

void DialogUserMdify::slotBtnShowHide()
{
    bool bChange=ui->lineEdit_passWord->echoMode()==QLineEdit::Password;
    if(bChange)
    {
        ui->lineEdit_passWord->setEchoMode(QLineEdit::Normal);
    }
    else
    {
        ui->lineEdit_passWord->setEchoMode(QLineEdit::Password);
    }
}

void DialogUserMdify::slotBtnIconSelect()
{
    QString iconPath =QFileHelper::FileSelect("Image files (*.png *.jpg)");
    if(iconPath.isEmpty())
        return;

    ui->lineEdit_IconPath->setText(iconPath);
}

void DialogUserMdify::showUserInfo()
{
    ui->lineEdit_userName->setText(m_userInfo.name());
    ui->lineEdit_passWord->setText(m_userInfo.password());
    ui->lineEdit_IconPath->setText(m_userInfo.iconPath());
    ui->comboBox_type->setCurrentText(m_userInfo.OperatorLevel());
}

void DialogUserMdify::setUserInfo()
{
    m_userInfo.setName(ui->lineEdit_userName->text());
    m_userInfo.setPassWord(ui->lineEdit_passWord->text());
    m_userInfo.setIconPath(ui->lineEdit_IconPath->text());
    m_userInfo.SetOperatorLevel(ui->comboBox_type->currentText());
}
